<template>
	<view class="auth" v-if="is_auth">  
		<view class="login-box">
			<view class="t1">授权登陆</view>
			<view class="t2">
				<img src="./wx_logo.png" />
				<view>申请获取以下权限</view>
			</view>
			<view class="t3">获得你的公开信息(名称、头像)</view>
			<view class="t4">
				<button size="mini" open-type="getUserInfo"  @click="getUserInfo"> 授权登陆 </button>
			 </view> 
		</view> 
	</view>
</template>

<script>
	export default {
		props:{
			is_auth:false
		},
		mounted() {
			console.log('挂载');
		},
		data() {
			return {  
				login:false,
				canIUseGetUserProfile:false
			};
		}, 
		created() {
			// #ifdef MP-WEIXIN						
				if (wx.getUserProfile) {
					console.log("新授权")
				  this.canIUseGetUserProfile=true
				}else{
					console.log("老授权")
				}
			// #endif
			
			
			// #ifdef MP-TOUTIAO
				if (uni.getUserProfile) {
					console.log("新授权")
				  this.canIUseGetUserProfile=true
				}else{
					console.log("老授权")
				}
			// #endif
		},
		methods: {
			getUserInfo(e){
				var that = this
				// #ifdef MP-WEIXIN
				wx.getUserProfile({
					lang:'zh_CN',
					desc: '用于展示自己的个人信息',
					success(res) {
						// console.log(res);
						let data = {
							nickname: res.userInfo.nickName,
							avatar: res.userInfo.avatarUrl
						}
						/* if (uni.getStorageSync('invite_id')) {
							data.invite_user = uni.getStorageSync('invite_id')
						} */
						that.$model.post("user/update_infor",data).then(res=>{
							that.$emit("send")
						})
					},
					fail(res) {
						
					},
				});
				// #endif
				
				// #ifdef MP-TOUTIAO
				uni.getUserProfile({
					lang:'zh_CN',
					desc: '用于展示自己的个人信息',
					success(res) {
						// console.log(res);
						let data = {
							nickname: res.userInfo.nickName,
							avatar: res.userInfo.avatarUrl
						}
						/* if (uni.getStorageSync('invite_id')) {
							data.invite_user = uni.getStorageSync('invite_id')
						} */
						that.$model.post("user/update_infor",data).then(res=>{
							that.$emit("send")
						})
					},
					fail(res) {
						
					},
				});
				// #endif
			},
		}
	}
</script>

<style lang="less">
	.auth {
		.login-box {
			position: absolute;
			left: 15%;
			top: 25%;
			z-index: 99999;
			border-radius: 20rpx;
			box-shadow: 1px 5px 3px #ccc;
			width: 70%;
			height: 439rpx;
			background: #FAF9FD;
			text-align: center;
		}

		.login-box .t1 {
			font-size: 32rpx;
			border-bottom: 1px solid #DEDEDE;
			padding: 7px 0;
		}

		.login-box .t2 {
			padding: 10rpx 0 10rpx;
			font-size: 30rpx;
		}

		.login-box .t2 image {
			width: 120rpx;
			height: 120rpx;
		}

		.login-box .t3 {
			font-size: 28rpx;
			color: #A8A7AB;
			padding-bottom: 20rpx;
		}

		.login-box .t4 {
			border-top: 1px solid #DEDEDE;
			padding: 10px 0 0;
		}

		.login-box .t4 button {
			font-size: 32rpx;
			color: #51C332;
			font-weight: 500;
		}
	}
</style>
